home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / RMISocketFactory.java < prev    next >
Text File  |  1998-09-22  |  3KB  |  104 lines

  1. /*
  2.  * @(#)RMISocketFactory.java    1.6 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.rmi.server;
  16.  
  17. import java.io.*;
  18. import java.net.*;
  19.  
  20. /**
  21.  * The RMISocketFactory is used by the RMI runtime in order to obtain
  22.  * client and server sockets for RMI calls. The default implementation
  23.  * of the socket factory performs a three-tiered approach to creating
  24.  * client sockets. First, a direct socket connection to the remote VM
  25.  * is attempted.  If that fails (due to a firewall), the runtime uses
  26.  * HTTP with the explicit port number of the server.  If the firewall
  27.  * does not allow this type of communication, then HTTP to a cgi-bin
  28.  * script on the server is used to POST the RMI call.
  29.  *
  30.  * An application may set the source of sockets for RMI. In this case,
  31.  * the application is responsible for offering up sockets that will
  32.  * penetrate a firewall.
  33.  */
  34. public abstract class RMISocketFactory {
  35.  
  36.     /** Client/server socket factory used by RMI */
  37.     private static RMISocketFactory factory = null;
  38.     /** Handler for socket creation failure */
  39.     private static RMIFailureHandler handler = null;
  40.  
  41.     /**
  42.      * Create a client socket connected to the specified host and port.
  43.      */
  44.     public abstract Socket createSocket(String host, int port)
  45.     throws IOException;
  46.  
  47.     /**
  48.      * Create a server socket on the specified port (port 0 represents
  49.      * an anonymous port).
  50.      */
  51.     public abstract ServerSocket createServerSocket(int port)
  52.     throws IOException;
  53.  
  54.     /**
  55.      * Set the socket factory from which RMI gets sockets. The RMI
  56.      * socket factory can only be set once. Note: The RMISocketFactory
  57.      * may only be set if the current security manager allows setting
  58.      * a socket factory; if disallowed, a SecurityException will be
  59.      * thrown.
  60.      */
  61.     public static void setSocketFactory(RMISocketFactory fac)
  62.     throws IOException
  63.     {
  64.         if (factory != null) {
  65.         throw new SocketException("factory already defined");
  66.     }
  67.     SecurityManager security = System.getSecurityManager();
  68.     if (security != null) {
  69.         security.checkSetFactory();
  70.     }
  71.     factory = fac;
  72.     }
  73.  
  74.     /**
  75.      * Returns the socket factory used by RMI.
  76.      */
  77.     public static RMISocketFactory getSocketFactory() 
  78.     {
  79.     return factory;
  80.     }
  81.  
  82.     /**
  83.      * Set the failure handler to be called by the RMI runtime if
  84.      * socket creation fails.  The default implementation of this
  85.      * handler returns false (thus recreation of sockets is not
  86.      * attempted by the runtime).
  87.      */
  88.     public static void setFailureHandler(RMIFailureHandler fh) 
  89.     {
  90.     handler = fh;
  91.     }
  92.  
  93.     /**
  94.      * Returns the handler for socket creation failure.
  95.      */
  96.     public static RMIFailureHandler getFailureHandler()
  97.     {
  98.     return handler;
  99.     }
  100. }
  101.  
  102.     
  103.     
  104.